
package com.siyoumi.app.service;

import com.siyoumi.app.entity.SysUv;
import com.siyoumi.app.mapper.SysUvMapper;
import com.siyoumi.component.http.XHttpContext;
import com.siyoumi.mybatispuls.JoinWrapperPlus;
import com.siyoumi.service.ServiceImplBase;
import com.siyoumi.component.XSpringContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


//t_sys_uv
@Slf4j
@Service
public class SysUvService
        extends ServiceImplBase<SysUvMapper, SysUv> {
    static public SysUvService getBean() {
        return XSpringContext.getBean(SysUvService.class);
    }

    /**
     * 总量
     *
     * @param idSrc
     * @param openid
     */
    public Long uvTotal(String idSrc, String openid) {
        JoinWrapperPlus<SysUv> query = join();
        query.eq("uv_x_id", XHttpContext.getX())
                .eq("uv_id_src", idSrc)
                .eq("uv_openid", openid);
        return count(query);
    }

    /**
     * 添加uv
     *
     * @param appId
     * @param idSrc
     * @param openid
     */
    public Boolean addUv(String appId, String idSrc, String openid) {
        SysUv uv = new SysUv();
        uv.setUv_app_id(appId);
        uv.setUv_x_id(XHttpContext.getX());
        uv.setUv_id_src(idSrc);
        uv.setUv_openid(openid);
        uv.setAutoID();

        boolean ok = false;
        try {
            ok = save(uv);
        } catch (Exception ex) {
            log.error(ex.getMessage());
        }

        return ok;
    }
}
